<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head>
    <title>系统权限管理</title>
    <meta charset="UTF-8" />
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="Author" content="larry" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <meta name="apple-mobile-web-app-status-bar-style" content="black"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no"/>
    <link rel="stylesheet" th:href="@{/static/larryms/layui/css/layui.css}" media="all" />
    <link rel="stylesheet" type="text/css" th:href="@{/static/larryms/css/admin/base.css}" media="all"/>
    <link rel="stylesheet" type="text/css" th:href="@{/static/larryms/css/admin/admin.css}" media="all"/>
    <link rel="stylesheet" type="text/css" href="http://at.alicdn.com/t/font_477590_nwvk1251e2m.css" media="all"/>
    <script type="text/javascript" th:src="@{/static/larryms/plus/jquery-3.2.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/static/larryms/layui/layui.all.js}"/>
    <script type="text/javascript" th:src="@{/static/scripts/common/tool.js}"></script>
    <meta http-equiv="pragma" content="no-cache"/>
    <meta http-equiv="cache-control" content="no-cache"/>
    <meta http-equiv="expires" content="0"/>
</head>
<body class="larryms-auth">
<div class="layui-row larryms-panel">
    <div class="larryms-panel-heading layui-col-lg12 layui-col-md12 layui-col-sm12 layui-col-xs12">
        <span class="panel-tit">系统权限管理</span>
    </div>
    <div class="larryms-panel-body layui-col-lg12 layui-col-md12 layui-col-sm12 layui-col-xs12">
        <div class="larryms-tools">
            <div class="larryms-btn-group" style="margin-top:10px">
                <span sec:authorize-expr="hasAnyAuthority('sys.menu.showAdd')">
                    <button class="layui-btn layui-btn-sm layui-btn-normal"  data-type="add">
                        <i class="layui-icon">&#xe61f;</i><cite>增加</cite></button>
                     <button class="layui-btn layui-btn-sm larryms-search"
                             onclick="javascript:location.replace(location.href);">
                            <i class="layui-icon layui-icon-refresh"></i></button>
                 </span>
            </div>
        </div>
        <div class="user-list layui-col-lg12 layui-col-md12 layui-col-sm12 layui-col-xs12">
            <!--<table id="roleList" lay-filter="roleList" class="larryms-table-id"
                   th:attr="data-url=@{/system/role/list}"></table>-->
            <table id="menuTree" class="layui-table" lay-filter="menuTree"></table>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" th:inline="javascript">/*<![CDATA[*/
    var deletePerm = /*[[${#authorization.expression("hasAnyAuthority('sys.menu.delete')")}]]*/ false;
    var updatePerm = /*[[${#authorization.expression("hasAnyAuthority('sys.menu.update')")}]]*/ false;
    function del(nodeId, text) {
        var index = layuiUtils.confirm('确定删除权限[<label style="color: #00AA91;">' + text + '</label>]?',function () {
            var url = /*[[@{/system/permission/delete}]]*/ "/system/permission/delete";
            layuiUtils.doRequest(url, {nodeId:nodeId}, function () {
                layer.close(index);
                location.replace(location.href);
            });
        })
    }
    function update(nodeId) {
        var url = /*[[@{/system/permission/showUpdate}]]*/ "/system/permission/showUpdate";
        url += '?nodeId=' + nodeId
        layuiUtils.dialog('permisUpdate','修改权限', url);
        $("div.layui-layer-iframe").addClass("larry-green");
    }

    function detail(nodeId) {
        var url = /*[[@{/system/permission/showUpdate}]]*/ "/system/permission/showUpdate";
        url += '?detail=true&nodeId=' + nodeId
        layuiUtils.dialog('permisDetail','查看权限详情', url);
        $("div.layui-layer-iframe").addClass("larry-green");
    }

    var baseUrl = /*[[@{/static/larryms/thirdlib/treetable/}]]*/ '/static/larryms/thirdlib/treetable/';
    layui.config({  base: baseUrl,});
    layui.use(['table','treetable', 'layer','jquery'], function () {
        var menus = [], layer = layui.layer, treetable = layui.treetable,$ = layui.$;
        var urlPermission = /*[[@{/system/permission/list}]]*/ "/system/permission/list";
        $.ajax({url: urlPermission, async: false, type: 'post', dataType:"json",
            success: function (result) {
                for(var n in result.data){
                    var item = result.data[n];
                    item.id = item.nodeId;
                    item.pid = item.pid ? item.pid : 0;
                    item.title = item.nameNode;
                    menus.push(item);
                }
            }
        });

        treetable.render({
            treeColIndex:1, //树形图标显示在第几列
            treeSpid:0,//最上级的父级id值
            elem: '#menuTree',
            treeIdName:"nodeId", //id字段的名称
            treePidName:"pid", //pid字段的名称
            treeDefaultClose: false,
            treeLinkage: true, //父级展开时是否自动展开所有子级
            data: menus,
            page: false,
            cols: [[
                {type: 'numbers'},
                { field: 'nameNode', title: '权限名称', width: '21%' },
                { field: 'nodeUrl', title: '权限URL', width: '30%' },
                { field: 'nodeCode', title: '权限', width: '15%' },
                { field: 'typeNode', title: '类型', width: '5%' , templet:function (d) {
                    return d.typeNode == '03' ? '菜单' : '功能';
                }},
                { field: 'icon', title: '图标', width: '5%', templet:function (d) {
                    return '<i class="larry-icon '+  (d.icon ? d.icon : '') + '"></i>';
                }},
                { field: 'isIndex', title: '状态', width: '5%', templet:function (d) {
                    return  d.isIndex == 1 ? '启用' : '停用';
                }},
                {field: 'actions',title: '操作',width: '16.2%', templet:function (d) {
                    var str = "";
                    if(updatePerm){
                        str = '<a class="layui-btn layui-btn-primary layui-btn-xs" onclick="detail(\'' + d.nodeId + '\')"><i class="larry-icon larry-file-markdown"></i> 查看</a>';
                        str +=  '<a class="layui-btn layui-btn-xs" onclick="update(\'' + d.nodeId + '\')"><i class="layui-icon">&#xe642;</i> 编辑</a>'; //列渲染
                    }

                    if (!d.isParent && deletePerm) {
                        str += '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="del(\'' + d.nodeId
                                + '\', \'' + d.nameNode + '\')"><i class="layui-icon">&#xe640;</i> 删除</a>';
                    }
                    return str;
                }}
            ]],
            done: function () {
                layer.closeAll('loading');
            }
        })

        var active = {
            add: function () {
                var url = /*[[@{/system/permission/showAdd}]]*/ "/system/permission/showAdd";
                layuiUtils.dialog('permisAdd','添加权限', url);
                $("div.layui-layer-iframe").addClass("larry-green");
            }
        }
        $('.larryms-btn-group .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
/*]]>*/</script>
</html>